define(function(require, exports, module) {
	require("pbbase/school/pageExtent/paginationE.js");
	var ajax = require("resource/js/component/ajax.js");
	var url = require("resource/js/component/urlTool.js");
	//initItem填充数据列表的函数   arrUrl数据数组访问地址  accUrl数据数量访问地址  pageKey分页的id para查询参数 idx页码 size每页数量
	exports.pages = function(initItem, arrUrl, pageKey, para, idx) {
		var pageIndex = 1;
		var pageSize =15;
		var items = [];
		//判断分页中是否有数据，无数据使用默认
		if(idx != 0 && typeof(idx) != undefined && typeof(idx) != 'undefined'){
			pageIndex = idx;
		}
		para.pageNo = pageIndex;
		para.pageSize = pageSize;
		var showBTN = function (){
			//var btnsshow =url.parseURL2JSON(url.getParam("buttons"));
			var pid = (this.app?this.app.pid:"")||url.getParam("pid");
			var flag =url.getParam("showBtnByUser");//showBtnByUser=yes 通过用户获取菜单权限
			var btnsshow = {};
			if(pid!=""&&pid!=null&&indexApp!=undefined){
				btnsshow = indexApp.exec("getButtons",pid);
			}else if(flag=="yes"||indexApp==undefined){
				ajax.init().success(function(code,msg,data){
					btnsshow=data;
				}).error(function(code,msg,data){
						$.messager.show({
							title:C.MESSAGE.MSGTITLE,
							msg:msg,
							timeout:2000,
							showType:'slide'
						});
				}).sync().post(BASEPATH+"/base/authoriza/func/getFuncByUrl.htm",{url:url.getFunUrl()});
			}
			if($.isEmptyObject(btnsshow)&&(!($.isEmptyObject(indexApp)))){
				btnsshow = indexApp.exec("getButtons");
			}
			if(!btnsshow)
				btnsshow={} ;
			var tmp =".north-toolbar";
			var btns = $(tmp).find("a");
			var btn_user_defined =  $(".btn_user_defined");
			$.each(btn_user_defined,function(i,_btn_user_defined){_btn_user_defined.defined=true});
			btns = $.merge(btns,btn_user_defined);
			$.each(btns,function(i,btn){
				if($(btn).attr("sign")=='sign'){
					return true;
				}
				$(btn).attr("sign","sign");
				if($(btn).hasClass("l-btn-display")&&!btn.defined){
					$(btn).closest("td").hide();
				}
				var opt ;
				if(btn.defined){
					opt = $(btn);
					opt.url=$(btn).attr("_url");
				}else{
					opt = $(btn).linkbutton("options");
				}
				
				var btnurl =opt.url;
				$.each(btnsshow,function(i,btnshow){
					if((btnshow.funUrl==BASEPATH+btnurl)||btnshow.link==btnurl){
						$(btn).removeClass("l-btn-display").addClass("btn_north");
						opt.funId=btnshow.funId;
						if(btnshow.funImg&&btnshow.funImg!=""){
							$(btn).find(".l-btn-icon").removeClass().addClass("l-btn-icon").addClass(btnshow.funImg);
						}
						if(!btn.defined){
							$(btn).closest("td").show();
						}
					}
				});
			});
		}
		ajax.init().success(function(code, msg, num_entries) {
                if(code == 0&&num_entries.total>0){
                    $(pageKey).paginationE(num_entries.total, {
                        callback : PageCallback,
                        items_per_page : pageSize,
                        num_edge_entries : 1, // 两侧首尾分页条目数
                        current_page : pageIndex, // 当前页索引
                    });
                }
		}).sync().post(BASEPATH + arrUrl, para);
		showBTN();
		// 翻页调用
		function PageCallback(index,pageSize,jq) {
			InitTable(index,pageSize);
		}
		
		// 请求数据
		function InitTable(pageIndex,pageSize) {
			para.pageSize = pageSize;
			para.pageNo = pageIndex;
			ajax.init().success(function(code, msg, data) {
				initItem(data);
			}).sync().post(BASEPATH + arrUrl, para);
		}
		return items;
	}
});
